//
//  MainNavC.m
//  BusinessMarket
//
//  Created by Michael Li on 2018/10/25.
//  Copyright © 2018年 Michael Li. All rights reserved.
//

#import "MainNavC.h"
#import "HomeTabVC.h"
#import "ServiceTheHallVC.h"
#import "MyCollectionVC.h"
//#import "WriteRequirementTabVC.h"
//#import "ReleaseSendModel.h"
@interface MainNavC ()

@end

@implementation MainNavC

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self.navigationBar setBackgroundImage:[ImageColorHelper createImageWithColor:kWhite] forBarMetrics:UIBarMetricsDefault];
    [self.navigationBar setShadowImage:[UIImage new]];
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new]
                                                 forBarPosition:UIBarPositionAny
                                                     barMetrics:UIBarMetricsDefault];
}
#pragma mark 返回按钮
-(void)popself {
    
    if (self.viewControllers.count>1) {
        [self popViewControllerAnimated:YES];
        
    }else {
        [self dismissViewControllerAnimated:YES completion:nil];
        
    }
}

#pragma mark 创建返回按钮
-(UIBarButtonItem *)createBackButton {
    UIImage *image = [[UIImage imageNamed:@"back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    return [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(popself)];
}

#pragma mark 重写方法
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    XLog(@"viewController.navigationItem.leftBarButtonItem:%@",viewController.navigationItem.leftBarButtonItem);
    XLog(@"self.viewControllers.count:%lu",(unsigned long)self.viewControllers.count);
    if (viewController.navigationItem.leftBarButtonItem == nil || [self.viewControllers count] > 1) {
        viewController.navigationItem.leftBarButtonItem =[self createBackButton];
    }
    if (self.viewControllers.count >0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
     [super pushViewController:viewController animated:animated];
}
-(void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
{
    if (viewControllerToPresent.navigationItem.leftBarButtonItem == nil && [self.viewControllers count] > 1) {
        
        viewControllerToPresent.navigationItem.leftBarButtonItem =[self createBackButton];
    }
}
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
{
    if (modalViewController.navigationItem.leftBarButtonItem == nil && [self.viewControllers count] > 1) {
        
        modalViewController.navigationItem.leftBarButtonItem =[self createBackButton];
        
    }
}

@end
